package com.yaopaikeji.mapper;

import com.yaopaikeji.model.RoleInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoleInfoMapper {

    @Insert("INSERT INTO role_info ( " +
            "                        role_name, " +
            "                        role_num," +
            "                        create_time " +
            ") VALUES              ( " +
            "                        #{roleName}, " +
            "                        #{roleNum}," +
            "                        #{createTime} " +
            ");")
    @SelectKey(statement = "select last_insert_id()",keyProperty = "id",before = false,resultType = int.class)
    int saveRoleInfo(RoleInfo roleInfo);

    @Select("Select * from role_info where id = #{id}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "role_name",property = "roleName"),
            @Result(column = "role_num",property = "roleNum"),
            @Result(column = "create_time",property = "createTime")
    })
    RoleInfo findByPrimaryKey(int id);

    @Select("Select * from role_info where role_name = #{name}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "role_name",property = "roleName"),
            @Result(column = "role_num",property = "roleNum"),
            @Result(column = "create_time",property = "createTime")
    })
    RoleInfo findByRoleName(String name);

    @Select("select * from role_info")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "role_name",property = "roleName"),
            @Result(column = "role_num",property = "roleNum"),
            @Result(column = "create_time",property = "createTime")
    })
    List<RoleInfo> findAll();

    @Select("select distinct(role_name) from role_info")
    List<String> findAllRoleNames();
}
